package com.yugao.fintech.antelope.gateway.config;

import com.yugao.fintech.antelope.gateway.sign.SignProperties;
import com.yugao.fintech.antelope.base.model.constants.CommonCons;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Data
@ConfigurationProperties(prefix = CommonCons.PROPERTIES_PREFIX + "gateway")
public class MyGatewayProperties {

    /**
     * 网关解密登录前端密码 秘钥
     */
    private String encodeKey;

    /**
     * 网关不需要校验验证码的客户端
     */
    private List<String> ignoreClients;

    private Auth auth = new Auth();

    /**
     * 签名数据
     */
    private List<SignProperties> sign = new ArrayList<>();


    /**
     * 文件配置
     */
    private List<UploadFileProperties> files = new ArrayList<>();

    /**
     * 忽略的租户url
     * @deprecated
     */
    private List<String> ignoreTenantUrls = new ArrayList<>();

    @PostConstruct
    public void init() {
        for (UploadFileProperties uploadFileProperties : files) {
            for (String bizUrl : uploadFileProperties.getBizUrls()) {
                UploadFileProperties.bizTypeMap.put(bizUrl, uploadFileProperties.getBizType());
            }
        }
    }

    @Getter
    @Setter
    public static class Auth {
        /**
         * 针对是否需要登录的排除接口
         */
        private List<String> excludePathForAuth = new ArrayList<>();
        /**
         * 针对是否需要校验权限的接口
         */
        private List<String> excludePathForPerm = new ArrayList<>();
    }
}
